{
    title:  'Deploying ESP Applications',
    crumbs: [
        { "User's Guide": 'index.html' },
    ],
}
        <h1>Deploying ESP Applications</h1>
        <p>When your ESP application has been built, you can select just the files and directories that are 
        required for deployment to the live site. For security, it is recommended that you <em>not</em> 
        copy the entire ESP application tree. Rather select only the files and directories that are actually
        required for the production application.</p>

        <h2>One Step Deploy</h2>

        <pre class="code">$ <b>expansive deploy</b></pre>

        <p>This copies the required files to the <em>./deploy</em> directory. You can also specify a deploy directory
        on the command line. For example:</p>

        <pre class="code">$ <b>expansive deploy /tmp/upload</b></pre>

        <p>This copies the required files to the <em>/tmp/upload</em> directory.</p>

        <h2>Files and Directories</h2>
        <p>These are the default files and directories that <em>expansive deploy</em> will deploy to the <em>./deploy</em>
            directory.</p>

        <table class="ui table" title="files">
            <thead>
                <tr><th>File/Directory</th><th>Contents</th></tr>
            </thead>
            <tbody>
                <tr>
                    <td>dist/</td>
                    <td>Public web content for the ESP application.</td>
                </tr>
                <tr>
                    <td>cache/</td>
                    <td>This directory contains the compiled ESP controllers and pages.</td>
                </tr>
                <tr>
                    <td>db/</td>
                    <td>Application database directory.</td>
                </tr>
                <tr>
                    <td>esp.json</td>
                    <td>The <em>esp.json</em> configures your ESP application.
                    </td>
                </tr>
                <tr>
                    <td>package.json</td>
                    <td>The <em>package.json</em> file defines the ESP application name and version.
                    </td>
                </tr>
            </tbody>
        </table>

        <h2>Customizing Deployment</h2>
        <p>The deploy command can be customized via the <em>control.deploy</em> property in the <em>expansive.json</em>
        file. For example:</p>

        <pre class="code">
{
    control: {
        deploy: {
            from: [
                "dist/**",
                "extra/*.pdf",
                "cache/*.dll",
                "cache/*.lib",
                "esp.json",
                "package.json"
            ],
            to: "deploy",
            clean: true,
            script: ''
        }
    }
}
</pre>
        <h3>Using <em>control.deploy</em> Properties</h3>
        <table class="ui table" title="deploy">
            <thead>
                <tr><th>Property</th><th>Description</th></tr>
            </thead>
            <tbody>
                <tr><td>from</td><td>Array of source files. May contain wild-cards. Defaults to:
                    <em>['dist/**', 'cache/*', 'package.json', 'esp.json']</em>.</td></tr>
                <tr><td>flatten</td><td>Do not preserve source directory structure. Defaults to <em>false</em>.</td></tr>
                <tr><td>to</td><td>Destination directory. Defaults to <em>./deploy</em>.</td></tr>
                <tr><td>clean</td><td>Remove the prior contents of the destination directory.</td></tr>
                <tr><td>script</td><td>Script to run after copying any specified files.</td></tr>
            </tbody>
        </table>

        <h3>Remote Deployment</h3>
        <p>You can use the <em>deploy.script</em> property to upload to a remote server. This example below creates
        a compressed tar file of the deploy contents and then uses a HTTP <em>put</em> request to upload to a server.</p>

        <pre class="code">
        {
  control: {
    deploy: {
      script: `
        require ejs.tar
        let file = Path('upload.tgz')
        Tar(file).create(Path('deploy').files('**', {directories: false}))
        let http = Http()
        http.put('http://example.com/' + file, file.readString())
        if (http.status != 200) {
            throw 'Cannot upload "' + file + '". Bad http status: ' + http.status  + '.'
        }
      `
    }
  }
}</pre>

        <h2>Deploying to different Architectures</h2>
        <p>If you are deploying to a different machine architecture, you will need to either cross-compile
        for that target or compile the ESP application on the target. 
        See <a href="building.html#target">Building for Target Systems</a> for more details.</p> 
